using LiteDB;

namespace PHMEE.VibrationDataGenerator.Data;

public class ChannelConfigRepository
{
    private readonly LiteDatabase _database;
    private readonly ILiteCollection<ChannelConfig> _channelConfigsCollection;

    public ChannelConfigRepository()
    {
        _database = new LiteDatabase(@"Filename=PhmVibGenerator.db; Connection=shared;");
        _channelConfigsCollection = _database.GetCollection<ChannelConfig>("channelConfigs");
    }

    public List<ChannelConfig> GetAllConfigs()
    {
        return _channelConfigsCollection.FindAll().ToList();
    }

    public ChannelConfig GetConfigById(ObjectId id)
    {
        return _channelConfigsCollection.FindById(id);
    }

    public void AddConfig(ChannelConfig config)
    {
        _channelConfigsCollection.Insert(config);
    }

    public void UpdateConfig(ChannelConfig config)
    {
        _channelConfigsCollection.Update(config);
    }

    public void DeleteConfig(ObjectId id)
    {
        _channelConfigsCollection.Delete(id);
    }
}